package com.shsxt.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.http.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alipay.api.AlipayApiException;
import com.shsxt.service.AuntService;
import com.shsxt.service.WodeService;
import com.shsxt.tokenlxc.AuthToken;
import com.shsxt.tokenlxc.Token;

import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;


@Controller
@RequestMapping("wode")
public class WodeController  {
	
	
	@Autowired
	private WodeService wodeService;
	@Autowired
	private AuntService auntService;
	//发送验证码
		@RequestMapping("sendCheck")
		public  @ResponseBody Map<String,Object> sendCheck(String phoneNumber,String type ) {
			Map<String,Object> map=wodeService.sendCheck(phoneNumber,type);
			return map;
		}

	//发送验证码
		@RequestMapping("sendCheck2")
		 @ResponseBody
		public  String sendCheck2(String phoneNumber,String type,String callback  ) {
			Map<String,Object> map=wodeService.sendCheck(phoneNumber,type);
			String a=callback + "({\"0\":\""+map.get("0")+"\"})";
			return a;
		}
	//验证登陆验证码
		@RequestMapping("login")
		public  @ResponseBody Map<String,Object> login(String phoneNumber,String type,String number) throws ParseException, APIConnectionException, APIRequestException {
			Map<String,Object> map=wodeService.login(phoneNumber,type,number);
			return map;
		}
		//验证登陆验证码
				@RequestMapping("login2")
				public  @ResponseBody String login2(String phoneNumber,String type,String number,String callback) throws ParseException, APIConnectionException, APIRequestException {
					Map<String,Object> map=wodeService.login(phoneNumber,type,number);
					String a=callback + "({\"0\":\""+map.get("0")+"\"})";
					return a;
				}
//退出登录
		@RequestMapping("loginout")
		public  @ResponseBody Map<String,Object> loginout(String phoneNumber) throws ParseException, APIConnectionException, APIRequestException {
			Map<String,Object> map=wodeService.loginout(phoneNumber);
			return map;
		}

   
    //点击我的(头像地址，昵称，用户等级,签到下面提示文字)
    @RequestMapping(value="wode")
	public  @ResponseBody Map<String,Object> findWodeMessage( String phoneNumber) throws ParseException {
    	Map<String,Object> wode = wodeService.findWodeMessages(phoneNumber);
		return wode;
	}
    @RequestMapping(value="notified")
	public  @ResponseBody Map<String, Object> notified(String phoneNumber ,String type) throws ParseException {
		Map<String, Object> map = auntService.notified(phoneNumber ,type);
		return map;
	}
	@RequestMapping(value="clickNotified")
	public  @ResponseBody Map<String, Object> clickNotified(String id ) {
		Map<String, Object> map = wodeService.clickNotified(id );
		return map;
	}
    //点击头像  ：个人中心(头像昵称类型性别出生手机号)
    @RequestMapping(value="personal")
	public  @ResponseBody Map<String,Object> findPersonalMessage( String phoneNumber ,HttpServletRequest request) throws ParseException {
    	Map<String,Object> list = wodeService.findMessages(phoneNumber,request);
    	
		return list;
	}
  //个人中心:保存(昵称类型性别出生手机号)
    @RequestMapping(value="updateP")
	public  @ResponseBody Map<String,Object> updatePersonalMessage(String petName,String sex,String birthday, String phoneNumber) throws ParseException, UnsupportedEncodingException {
    	Map<String,Object> result = wodeService.updateMessages(petName,sex,birthday,phoneNumber);
		return result;
	}
    
  //返回储存头像地址的文件夹,并将完路径的头像地址存到数据库
    @RequestMapping(value="head")
	public  @ResponseBody Map<String,Object> findHeadFolder(HttpSession session,String phoneNumber,HttpServletRequest request,
			HttpServletResponse response) throws IllegalStateException, IOException, ParseException {
    	Map<String, Object> map=wodeService.updateHeadStr(session,phoneNumber,request,response);
		return map;
	}

  //点击普通用户： 用户经验和等级(经验值等级差多少升级)
	@RequestMapping("level")
	public  @ResponseBody Map<String,Object> findlevel(String phoneNumber) throws ParseException {
		Map<String,Object> level=wodeService.levelMessages(phoneNumber);
		return level;
	}
	//点击签到有奖： 签到奖励积分(签到成功字符串)
	
		@RequestMapping("signin")
		public  @ResponseBody Map<String,Object> findSignIn(String phoneNumber) throws ParseException {
			Map<String,Object> signIn=wodeService.signInMessages(phoneNumber);
			return signIn;
		}
		//邀请有礼(url,已邀请几次)
			@RequestMapping("invite")
			public  @ResponseBody Map<String,Object> invite(String phoneNumber) throws ParseException {
				
				Map<String,Object> list=wodeService.invite(phoneNumber);
				return list;
			}
			
	//获取所有小区
		@RequestMapping("location")
		public  @ResponseBody Map<String,Object> house() throws ParseException {
			Map<String,Object> map=wodeService.house();
			return map;
		}
		@RequestMapping("loca")
		public  @ResponseBody List loca() throws ParseException {
			List list=wodeService.loca();
			return list;
		}
		@RequestMapping("sType")
		public  @ResponseBody List sType() throws ParseException {
			List list=wodeService.sType();
			return list;
		}
		// //我的：地址(此用户所有地址：地址默认手机号)
		@RequestMapping("address")
		public  @ResponseBody Map<String,Object> findAddress(String phoneNumber) throws ParseException {
			Map<String,Object> addressMessages=wodeService.addressMessages(phoneNumber);
			return addressMessages;
		}


		/*//获取添加地址token
		@RequestMapping(value="getToken")
		@Token(save=true)
		public  @ResponseBody Map<String,Object> addAddressBefore(HttpServletRequest request)  {
			Map<String,Object> map=new HashMap<String,Object>();
			 map.put("token", request.getSession().getAttribute("token"));
			return map;
		}*/
		//我的：地址：添加新地址？手机,地址,实际手机号码，详细地址，默认	
		@RequestMapping(value="addAddress")
		public  @ResponseBody Map<String,Object> addAddress(String phoneNumber,String address,String realPhoneNumber,String detailAddress,String tag,String location) throws UnsupportedEncodingException, ParseException {
			Map<String,Object> map=wodeService.addAddress(phoneNumber,address,realPhoneNumber,detailAddress,tag,location);
			return map;
		}
	//我的：地址：编辑地址:保存?uuid,地址,实际手机,详细地址,默认
		@RequestMapping(value="saveAddress")
		public  @ResponseBody Map<String,Object> saveAddress(String uuid,String address,String realPhoneNumber,String detailAddress,String tag,String location) throws UnsupportedEncodingException {
			Map<String,Object> map=wodeService.saveAddress( uuid, address, realPhoneNumber, detailAddress, tag,location);
			return map;
		}
	//删除地址
		@RequestMapping(value="deleteAddress")
		public  @ResponseBody Map<String,Object> deleteAddress(String uuid)  {
			Map<String,Object> map=wodeService.deleteAddress(uuid);
			return map;
		}
//详情地址
		@RequestMapping(value="detailAddress")
		public  @ResponseBody Map<String,Object> detailAddress(String uuid)  {
			Map<String,Object> map=wodeService.detailAddress(uuid);
			return map;
		}
	//地址：默认
		@RequestMapping(value="defaultAddress")
		public  @ResponseBody Map<String,Object> defaultAddress(String uuid) throws UnsupportedEncodingException {
			Map<String,Object> map=wodeService.defaultAddress(uuid);
			return map;
		}
	//点击会员卡： 当前余额
	@RequestMapping("memberBalance")
	public  @ResponseBody Map<String,Object> findMemberBalance(String phoneNumber) {
		Map<String,Object> balance=wodeService.memberBalanceMessages(phoneNumber);
		return balance;
	}
	//15点击积分： 用户积分//查询用户的积分明细
		@RequestMapping("credits")
		public  @ResponseBody Map<String,Object> findCredits(String phoneNumber) {
			Map<String,Object> credits=wodeService.creditsMessages(phoneNumber);
			return credits;
		}
		//16该用户所有优惠券
		@RequestMapping("coupon")
		public  @ResponseBody Map<String,Object> findCoupon(String phoneNumber) {
			Map<String,Object> credits=wodeService.findCoupon(phoneNumber);
			return credits;
		}
		
	//17设置：用户反馈?手机号反馈
			@RequestMapping("feedBack")
			public  @ResponseBody Map<String,Object> addFeedBack(String phoneNumber,String text) {
				wodeService.addFeedBack(phoneNumber,text);
				Map<String,Object> a=new HashMap<String,Object>();
				a.put("0", "成功");
				return a;
			}
		//17余额支付 购买会员卡
		@RequestMapping("balancePaid")
		public  @ResponseBody Map<String,Object> balancePaid(String orderNumber,String type,String redeemCode) {
			Map<String,Object> a=wodeService.balancePaid(orderNumber,type,redeemCode);
			return a;
		}
		
		

	//token---------------------------------------------------------------------
			
		/*	@RequestMapping(value = "/headFolder")
			 @ResponseBody
			 public Map<String, Object> headImgUpload(HttpServletRequest request,HttpSession session,String phoneNumber) throws Exception {
			   Map<String, Object> map = new HashMap<String, Object>();
			     String head = wodeService.updateHead(request,session,phoneNumber);//此处是调用上传服务接口，4是需要更新的userId 测试数据。
			     map.put("0", head);
			   return map;
			 }*/
			@RequestMapping(value = "/headTest")
			 @ResponseBody
			 public Map<String, Object> headTest(HttpServletRequest request,HttpSession session,String phoneNumber) throws Exception {
			   Map<String, Object> map = new HashMap<String, Object>();
			     String head = wodeService.headTest( request, session,phoneNumber);//此处是调用上传服务接口，4是需要更新的userId 测试数据。
			     map.put("0", head);
			   return map;
			 }
	
		//发送验证码
				@RequestMapping("ceshi")
				public  @ResponseBody Map<String,Object> ceshi() throws APIConnectionException, APIRequestException {
					Map<String,Object> map=wodeService.ceshi();
					return map;
				}

				@RequestMapping("shibie")
				public  @ResponseBody void shibie() throws APIConnectionException, APIRequestException, InterruptedException, AlipayApiException {
					wodeService.shibie();
				}

		//发送验证码
				/*@RequestMapping("daojishi")
				public  @ResponseBody Map<String,Object> daojishi(JobExecutionContext arg0) throws InterruptedException, JobExecutionException {
					Map<String,Object> map=wodeService.daojishi(arg0);
					return map;
				}*/
	
}
